package com.ad.pet.app.login;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;

import com.ad.pet.DaggerMainActivityCompent;
import com.ad.pet.R;
import com.ad.pet.app.RxDisposable;
import com.ad.pet.app.login.fragment.AccountLoginContract;
import com.ad.pet.app.login.fragment.AccountLoginPresenter;
import com.ad.pet.common.data.utils.SpUtil;
import com.ad.pet.common.data.utils.ui.ToastUtil;
import com.ad.pet.common.structure.mvp.BasePresenter;
import com.ad.pet.common.structure.ui.activity.AppToolbarActivity;
import com.ad.pet.constant.Constant;
import com.ad.pet.models.remote.User;
import com.ad.pet.ui.InputView;

import javax.inject.Inject;

import butterknife.BindView;

/**
 * Created by SEELE on 2019/3/11.
 */

public class ResetPwdActivity extends AppToolbarActivity implements AccountLoginContract.View {

    @Inject
    AccountLoginPresenter mLoginPresenter;
    @BindView(R.id.et_old_pwd)
    InputView mEtOldPwd;
    @BindView(R.id.et_new_pwd)
    InputView mEtNewPwd;
    @BindView(R.id.et_confirm_new_pwd)
    InputView mEtConfirmNewPwd;
    @BindView(R.id.btn_commit)
    Button mBtnCommit;


    @Inject
    RxDisposable mRxDisposable;

    @Override
    protected void init(Bundle savedInstanceState) {
        super.init(savedInstanceState);
        mStatusLayoutManager.showContent();
//        mToolbar.setTitle(R.string.reset_pwd);

    }

    @Override
    protected int contentLayout() {
        return R.layout.acitivyt_reset_pwd;
    }

    @Override
    protected void clickRetry(View v) {

    }

    @Override
    protected void initViews() {
        mLoginPresenter.onCreate(this);

    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initEvents() {


        mBtnCommit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (TextUtils.isEmpty(mEtOldPwd.getContent())){
                    ToastUtil.getToastUtil().showShort(mEtOldPwd.getEtContent().getHint().toString());
                }
                if (TextUtils.isEmpty(mEtNewPwd.getContent())){
                    ToastUtil.getToastUtil().showShort(mEtNewPwd.getEtContent().getHint().toString());
                }
                if (TextUtils.isEmpty(mEtConfirmNewPwd.getContent())){
                    ToastUtil.getToastUtil().showShort(mEtConfirmNewPwd.getEtContent().getHint().toString());
                }
                if (!TextUtils.equals(mEtConfirmNewPwd.getContent(),mEtNewPwd.getContent())){
                    ToastUtil.getToastUtil().showShort("两次输入密码不一致");
                }
                mLoginPresenter.resetPassword(mEtOldPwd.getContent(), mEtNewPwd.getContent(), mEtConfirmNewPwd.getContent());
            }
        });
    }

    @Override
    public void initInject() {
        DaggerMainActivityCompent.builder().applicationComponent(getApplicationComponent()).activityModule(getActivityModule()).build().inject(this);
    }

    @Override
    protected BasePresenter getPresenter() {
        return null;
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void error(String msg) {
        ToastUtil.getToastUtil().showShort(msg);
    }

    @Override
    public void error(int code, String msg) {
        ToastUtil.getToastUtil().showShort(msg);
    }

    @Override
    public void phoneLoginSuccess(User user) {

    }

    @Override
    public void accountLoginSuccess(User user) {

    }

    @Override
    public void getEmailCodeSuccess() {

    }

    @Override
    public void forgetPwdResetSuccess() {

    }

    @Override
    public void resetPwdSuccesss() {

        Intent intent = new Intent();
        intent.putExtra("goHome",1);
        SpUtil.getInstance().putString(Constant.ACCESS_TOKEN,"");
        ToastUtil.getToastUtil().showShort(getString(R.string.reset_pwd_success_tips));
        setResult(RESULT_OK,intent);
        finish();
    }

    @Override
    public void registJpushSuccess() {

    }


}
